package com.web.controller;

import com.alibaba.fastjson2.JSON;
import com.web.entity.ResponseResult;
import com.web.entity.Student;
import com.web.service.StudentService;
import com.web.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 删除学生的数据接口
 */
@WebServlet("/deleteStudent")
public class DeleteStudentServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得学生信息参数
        String sId = req.getParameter("id");
        int id = 0;
        if(sId != null){
            id = Integer.parseInt(sId);
        }

        //删除学生
        StudentService studentService = new StudentServiceImpl();
        studentService.removeStudent(id);
        //返回消息
        resp.getWriter().write(JSON.toJSONString(new ResponseResult(200,"OK",null)));
    }
}
